import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';

/** 值类型枚举 */
export enum ValueTypeEnum {
  /** 任意 */
  Any = 0,
  /** Bit */
  Bit = 1,
  /** Boolean */
  Boolean = 2,
  /** SByte */
  SByte = 3,
  /** Byte */
  Byte = 4,
  /** Int16 */
  Int16 = 5,
  /** UInt16 */
  UInt16 = 6,
  /** Int32 */
  Int32 = 7,
  /** UInt32 */
  UInt32 = 8,
  /** Int64 */
  Int64 = 9,
  /** UInt64 */
  UInt64 = 10,
  /** Int128 */
  Int128 = 11,
  /** UInt128 */
  UInt128 = 12,
  /** Float */
  Float = 13,
  /** Double */
  Double = 14,
  /** String */
  String = 15,
  /** DateTime */
  DateTime = 16,
  /** TimeSpan */
  TimeSpan = 17,
  /** Guid */
  Guid = 18,
  /** Bcd16 */
  Bcd16 = 19,
  /** Bcd32 */
  Bcd32 = 20,
}

/** 值类型实体 */
export class ValueTypeEntity {
  /** 值类型 */
  ValueType: ValueTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(valueType: ValueTypeEnum, color?: PresetColorEnum | string) {
    this.ValueType = valueType;
    this.Color = color;
    switch (valueType) {
      case ValueTypeEnum.Any:
        this.Display = 'Any';
        this.Color = this.Color ? this.Color : PresetColorEnum.Default;
        break;
      case ValueTypeEnum.Bit:
        this.Display = 'Bit';
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case ValueTypeEnum.Boolean:
        this.Display = 'Boolean';
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case ValueTypeEnum.SByte:
        this.Display = 'SByte';
        this.Color = this.Color ? this.Color : PresetColorEnum.Cyan;
        break;
      case ValueTypeEnum.Byte:
        this.Display = 'Byte';
        this.Color = this.Color ? this.Color : PresetColorEnum.Cyan;
        break;
      case ValueTypeEnum.Int16:
        this.Display = 'Int16';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.UInt16:
        this.Display = 'UInt16';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.Int32:
        this.Display = 'Int32';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.UInt32:
        this.Display = 'UInt32';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.Int64:
        this.Display = 'Int64';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.UInt64:
        this.Display = 'UInt64';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.Int128:
        this.Display = 'Int128';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.UInt128:
        this.Display = 'UInt128';
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case ValueTypeEnum.Float:
        this.Display = 'Float';
        this.Color = this.Color ? this.Color : PresetColorEnum.Gold;
        break;
      case ValueTypeEnum.Double:
        this.Display = 'Double';
        this.Color = this.Color ? this.Color : PresetColorEnum.Gold;
        break;
      case ValueTypeEnum.String:
        this.Display = 'String';
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case ValueTypeEnum.DateTime:
        this.Display = 'DateTime';
        this.Color = this.Color ? this.Color : PresetColorEnum.Lime;
        break;
      case ValueTypeEnum.TimeSpan:
        this.Display = 'TimeSpan';
        this.Color = this.Color ? this.Color : PresetColorEnum.Lime;
        break;
      case ValueTypeEnum.Guid:
        this.Display = 'Guid';
        this.Color = this.Color ? this.Color : PresetColorEnum.Magenta;
        break;
      case ValueTypeEnum.Bcd16:
        this.Display = 'Bcd16';
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
      case ValueTypeEnum.Bcd32:
        this.Display = 'Bcd32';
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
    }
  }
}

//#region 获取值类型枚举架构
/**
 * 获取值类型枚举架构
 */
export function getValueTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: ValueTypeEntity[] = [
    new ValueTypeEntity(ValueTypeEnum.Any),
    new ValueTypeEntity(ValueTypeEnum.Bit),
    new ValueTypeEntity(ValueTypeEnum.Boolean),
    new ValueTypeEntity(ValueTypeEnum.SByte),
    new ValueTypeEntity(ValueTypeEnum.Byte),
    new ValueTypeEntity(ValueTypeEnum.Int16),
    new ValueTypeEntity(ValueTypeEnum.UInt16),
    new ValueTypeEntity(ValueTypeEnum.Int32),
    new ValueTypeEntity(ValueTypeEnum.UInt32),
    new ValueTypeEntity(ValueTypeEnum.Int64),
    new ValueTypeEntity(ValueTypeEnum.UInt64),
    new ValueTypeEntity(ValueTypeEnum.Int128),
    new ValueTypeEntity(ValueTypeEnum.UInt128),
    new ValueTypeEntity(ValueTypeEnum.Float),
    new ValueTypeEntity(ValueTypeEnum.Double),
    new ValueTypeEntity(ValueTypeEnum.String),
    new ValueTypeEntity(ValueTypeEnum.DateTime),
    new ValueTypeEntity(ValueTypeEnum.TimeSpan),
    new ValueTypeEntity(ValueTypeEnum.Guid),
    new ValueTypeEntity(ValueTypeEnum.Bcd16),
    new ValueTypeEntity(ValueTypeEnum.Bcd32),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.ValueType as number,
      label: item.Display,
      value: item.ValueType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
